import { createBrowserRouter, Navigate } from 'react-router-dom'
//路由懒加载，按需加载组件
import { Suspense, lazy } from "react"
// 懒加载组件形式
const Home = lazy(() => import('@/pages/Home/index.js'))
const Layout = lazy(() => import('@/pages/Layout/layout.js'))
// 非懒加载组件形式
// import Home from '@/pages/Home/index.js'
const CityList = lazy(() => import("@/pages/CityList/index.js"))
const HouseList = lazy(() => import("@/pages/HouseList/index.js"))
const News = lazy(() => import("@/pages/News/index.js"))
const Profile = lazy(() => import("@/pages/Profile/index.js"))
const Map = lazy(() => import("@/pages/Map/index.js"))
const router = createBrowserRouter([
    {
        path: '/',//设置重定向到首页页面
        element: <Navigate to="/home"></Navigate>,
    },
    {
        path: '/home',//设置重定向到首页子页面
        element: <Navigate to="/home/index"></Navigate>,
    },
    {//首页路由信息
        path: '/home',
        element: <Suspense fallback={'加载中...'}><Layout /></Suspense>,
        children: [
            {//首页
                path: 'index',
                element: <Suspense fallback={'加载中...'}><Home /></Suspense>,
                index: true, // 没有path设置,index设置为true 变成默认的二级路由
            },
            {//找房页面
                path: 'houselist',
                element: <Suspense fallback={'加载中...'}><HouseList /></Suspense>,
            },
            {//咨询页面
                path: 'news',
                element: <Suspense fallback={'加载中...'}> <News /></Suspense>,
            },
            {//个人中心页面
                path: 'profile',
                element: <Suspense fallback={'加载中...'}><Profile /></Suspense>,
            },

        ],
    },
    {//地图组件路由信息
        path: '/map',
        element: <Suspense fallback={'加载中...'}><Map /></Suspense>
    },
    {//城市选择路由信息
        path: '/cityList',
        element: <Suspense fallback={'加载中...'}><CityList /></Suspense>
    }
])

export default router